package dao.reader.impl;

import dao.BaseDao;
import dao.reader.Borrow_cardDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Borrow_cardDaoImpl
 *
 * @author 谭文斌
 * @since 2023/8/25
 */
public class Borrow_cardDaoImpl extends BaseDao implements Borrow_cardDao {
    @Override
    public String login(String user, String password) {
        int row = 0;
        if (user.trim().equals("")) {
            return "账号不能为空";
        }
        if (password.trim().equals("")) {
            return "密码不能为空";
        }
        String sql = "select Count(*) as c from borrow_card where id=?  and  password = ?";
        Connection conn = getConnection();
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = conn.prepareStatement(sql);
            ps.setString(1, user);
            ps.setString(2, password);
            rs = ps.executeQuery();
            while (rs.next()) {
                row = rs.getInt("c");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            closeAll(rs, ps, conn);
        }
        return row == 0 ? "账号或密码错误！" : String.valueOf(row);
    }
}
